# Maintainer: David Runge <dvzrv@archlinux.org>

_name=pywlroots
pkgname=python-pywlroots
pkgver=0.15.24
pkgrel=4
pkgdesc="Python binding to the wlroots library using cffi"
arch=(loong64 x86_64)
url="https://github.com/flacjacket/pywlroots"
license=(custom:UIUC)
depends=(glibc python-cffi python-pywayland python-xkbcommon wlroots0.15 libwlroots.so=10)
makedepends=(python-build python-installer python-setuptools python-wheel)
checkdepends=(python-pytest)
provides=(pywlroots)
conflicts=(pywlroots)
replaces=(pywlroots)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha512sums=('65105d163ade1036d8db634bd30e0b42ad95149298b05accab22865b17a6055b20028271f9e07269aea97eb0028a8b66773005511d5c64602d532413203e3ebc')
b2sums=('a89099cd1aab761b06ba53a19b49b5ad66b8fcd19e7c9dea64ebffb3fc5e163076e6ea9b91b12c2f66cebfec9f0673268dd8bdebd29270a6786df3fe7b8037d0')

build() {
  export CFLAGS="$CFLAGS -I/usr/include/wlroots0.15"
  export LDFLAGS="$LDFLAGS -L/usr/lib/wlroots0.15"
  cd $_name-$pkgver
  python wlroots/ffi_build.py
  python -m build --wheel --no-isolation
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
  pytest -vv
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 README.rst -t "$pkgdir/usr/share/doc/$pkgname"
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}
